package com.study.homework;

public class LinkedQueue {

    DouLinkedNode head;
    DouLinkedNode tail;

    public int push(int a) {
        DouLinkedNode node = new DouLinkedNode(a);
        if (head == null || tail == null) {
            head = tail = node;
            return a;
        }

        node.pre = head;
        head.next = node;
        head = node;

        return a;
    }

    public int pop() {
        DouLinkedNode node = this.tail;
        if (tail == null) {
            return -1;
        }
        if(tail == head){
            return tail.val;
        }

        tail = tail.next;
        tail.pre = null;
        node.next = null;
        return node.val;
    }

    public int peek() {
        return tail == null ? -1 : tail.val;
    }

}
